# -*- coding: utf-8 -*-
import pymysql
result = []
with open('./db_connection.txt','r',encoding='utf-8') as f:
    for line in f.readlines():
        line = line.rstrip("\n")
        list = line.split(",",6)
        IP = list[0]
        PORT = list[1]
        USER = list[2]
        DBNAME = list[3]
        PASSWORD = list[4]
        GAME_NAME = list[5]

        db = pymysql.connect(
                host = IP,
                port = int(PORT),
                user = USER,
                passwd = PASSWORD,
                db = DBNAME
        )
        cursor = db.cursor()
        sql = "select count(*) from user_inf;"
        try:
            cursor.execute(sql)
            result = cursor.fetchall()
            for row in result:
                count = row[0]
                print(GAME_NAME,"user_inf count: %s" % count)
        except:
                print("Error: unable to fetch data")
db.close()
f.close()
print("以上为每个游戏用户总数")